﻿using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace CustomWindows.Window_API
{
    public class ToggleScreenState: WindowsFunction
    {
        public enum nCmdShow
        {
            NORMAL = 1,
            MIN = 2,
            MAX = 3
        }

        private struct WindowPlacement
        {
            public int length;
            public int flags;
            public int showCmd;
            public Point ptMinPosition;
            public Point ptMaxPosition;
            public Rectangle rcNormalPosition;
        }

		#region Constructors (1) 

        public ToggleScreenState(IntPtr hwnd) : base(hwnd)
        {
            Description = "MaxScreen";
            EventLogger = new Event(DateTime.Now, Hwnd, Description);
        }

		#endregion Constructors 

		#region Methods (1) 

		// Public Methods (1) 

        public override void UpdateFunction()
        {

            WindowPlacement wp = new WindowPlacement();
            GetWindowPlacement(Hwnd, ref wp);

            nCmdShow windowState = nCmdShow.NORMAL;
            switch(wp.showCmd)
            {
                case (int)nCmdShow.MAX:
                    windowState = nCmdShow.MIN;
                    break;
                case (int)nCmdShow.NORMAL:
                    windowState = nCmdShow.MAX;
                    break;
                case (int)nCmdShow.MIN:
                    windowState = nCmdShow.NORMAL;
                    break;
            }

            ShowWindowAsync(Hwnd, (int)windowState);

        }

		#endregion Methods 

        #region API

        [DllImport("user32.dll")]
        private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
        [DllImport("user32.dll")]
        private static extern bool GetWindowPlacement(IntPtr hWnd, ref WindowPlacement lpwndpl);

        #endregion
    }
}
